package org.example.modules.user.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.example.common.utils.ThreadLocalUtil;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.UserWallet;
import org.example.modules.user.entry.WalletDetails;
import org.example.modules.user.service.UserWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description UserWalletController
 * @Author xiaotian
 * @Date 2025-04-20
 */
@RestController
@RequestMapping("/wxApi/wallet")
@Slf4j
public class UserWalletController {
    @Autowired
    private UserWalletService userWalletService;

    /**
     * 获取钱包余额
     *
     * @return 钱包余额
     */
    @GetMapping("/balance")
    public Commsult<UserWallet> getWalletBalance() {
        return Commsult.success(userWalletService.getWalletBalance(ThreadLocalUtil.getUserId()));
    }

    /**
     * 获取钱包详情
     * @return
     */
    @GetMapping("/details")
    public Commsult<List<WalletDetails>> getWalletDetails() {
        return Commsult.success(userWalletService.getWalletDetails());
    }

    /**
     * 提交充值
     *
     * @param request 充值请求参数
     * @return 操作结果
     */
    @PostMapping("/recharge")
    public Commsult recharge(@RequestBody JSONObject request) {
        userWalletService.recharge(request);
        return Commsult.success("充值成功");
    }

    /**
     * 提交提现
     *
     * @param request 提现请求参数
     * @return 操作结果
     */
    @PostMapping("/withdraw")
    public Commsult withdraw(@RequestBody JSONObject request) {
        userWalletService.withdraw(request);
        return Commsult.success("提现成功");
    }
}
